{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# opencv 演示"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "安装opencv-python包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n",
      "Requirement already satisfied: opencv-python==4.1.1.26 in c:\\users\\zhenchen\\appdata\\local\\programs\\python\\python37\\lib\\site-packages (4.1.1.26)\n",
      "Requirement already satisfied: numpy>=1.14.5 in c:\\users\\zhenchen\\appdata\\local\\programs\\python\\python37\\lib\\site-packages (from opencv-python==4.1.1.26) (1.17.2)\n"
     ]
    }
   ],
   "source": [
    "!pip install opencv-python==4.1.1.26 -i https://pypi.tuna.tsinghua.edu.cn/simple"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "导入cv2库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "打开摄像头"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "imcap = cv2.VideoCapture(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "显示拍摄画面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "while(1):\n",
    "    # get a frame\n",
    "    ret, frame = imcap.read()\n",
    "    cv2.startWindowThread()\n",
    "    # show a frame\n",
    "    cv2.imshow(\"capture\", frame)\n",
    "    if cv2.waitKey(1) & 0xFF == ord('q'):\n",
    "        break\n",
    "imcap.release()\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
